//
//  ACCache.h
//  ACCache_Example
//
//  Created by autohome on 2021/8/7.
//  Copyright © 2021 CaiXiang. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ACMemoryCache.h"
#import "ACDiskCache.h"
#import "ACCacheConfiguration.h"

NS_ASSUME_NONNULL_BEGIN

@interface ACCache : NSObject

@property (strong, nonatomic, readonly) ACCacheConfiguration *config;
@property (strong, nonatomic,readonly) ACMemoryCache *memoryCache;
@property (strong, nonatomic,readonly) ACDiskCache *diskCache;

+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;

/// 初始化
/// 使用指定的名称创建一个新实例
/// 具有相同名称的多个实例将使缓存不稳定
///
/// @param config 缓存配置
+ (instancetype)cacheWithConfiguration:(ACCacheConfiguration *)config;

@end

@interface ACCache (ACExtension)

/// 在缓存设置键值对
/// @param object 缓存对象
/// @param key 缓存唯一标识
- (void)setObject:(nullable id<NSCoding>)object forKey:(NSString *)key;

/// 在缓存设置键值对
/// @param object 缓存对象
/// @param key 缓存唯一标识
/// @param yesOrNo 是否写入磁盘缓存
- (void)setObject:(nullable id<NSCoding>)object forKey:(NSString *)key toDisk:(BOOL)yesOrNo;

/// 在缓存设置键值对多参数
/// @param object 缓存对象一
/// @param vaule 缓存对象二
/// @param key 缓存对象一和二共同组成的字典对应的唯一标识
- (void)setObject:(nullable id<NSCoding>)object vaule:(nullable id<NSCoding>)vaule forKey:(NSString *)key;

/// 在缓存设置键值对多参数
/// @param object 缓存对象一
/// @param vaule 缓存对象二
/// @param key 缓存对象一和二共同组成的字典对应的唯一标识
/// @param yesOrNo 是否写入磁盘缓存
- (void)setObject:(nullable id<NSCoding>)object vaule:(nullable id<NSCoding>)vaule forKey:(NSString *)key toDisk:(BOOL)yesOrNo;

@end

@interface ACCache (Extension)

/// 该值指示给定键是否在缓存中
/// @param key 标识值的字符串。如果是nil，就返回NO
- (BOOL)containsObjectForKey:(NSString *)key;

/// 获取缓存
/// @param key 缓存唯一标识
- (nullable id)objectForKey:(NSString *)key;

/// 移除缓存
/// @param key 缓存唯一标识
- (void)removeObjectForKey:(NSString *)key;

/// 移除所有缓存
- (void)removeAllObjects;

@end

NS_ASSUME_NONNULL_END
